#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
#   GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
#   Author :  Shawn.Tan
#   Date : 2025.10.28
#
#   History : Initial Version 2025.10.28
#
#
from base.InstructionMap import InstructionMap

"""

------------------------------------------------------------------------------
------------------------------------------------------------------------------
Groupings from ISA instruction listings

References...
  The GPGPU Instruction Set Manual, Volume I: Unprivileged ISA
  > Chapter 24 - PB1PB100 GPGPU Instruction Set Listings
  > ISA Spec Version 11.21
------------------------------------------------------------------------------

Extension       Component extensions and/or instructions
------------------------------------------------------------------------------
IALU             partially compieted

Additional groups focused on functional units
----------------------------------------------------------


==============================================================================
"""


# Utility function used to combine multiple dictionaries into one
def merge(*args):
    result = {}
    for dict1 in args:
        result.update(dict1)
    return result


IALU_instructions ={
    "IADD_RR##CALM"           : 10,
    "IADD_RU##CALM"           : 10,
    "IADD_RI##CALM"           : 10,
    "IADD_RC##CALM"           : 10,
    "IADD_RR#NoCarry#CALM"    : 10,
    "IADD_RU#NoCarry#CALM"    : 10,
    "IADD_RI#NoCarry#CALM"    : 10,
    "IADD_RC#NoCarry#CALM"    : 10,
    "IADD_RR#R64#CALM"        : 10,
    "IADD_RU#R64#CALM"        : 10,
    "IADD_RI#R64#CALM"        : 10,
    "IADD_RC#R64#CALM"        : 10,
    "IADD_RR#R64NoCarry#CALM" : 10,
    "IADD_RU#R64NoCarry#CALM" : 10,
    "IADD_RI#R64NoCarry#CALM" : 10,
    "IADD_RC#R64NoCarry#CALM" : 10,
    "IMAD_RRR##CALM"          : 10,
    "IMAD_RRI##CALM"          : 10,
    "IMAD_RIR##CALM"          : 10,
    "IMAD_RRC##CALM"          : 10,
    "IMAD_RCR##CALM"          : 10,
    "IMAD_RRU##CALM"          : 10,
    "IMAD_RRU##CALM"          : 10,
    "IMAD_RRR#HI#CALM"        : 10,
    "IMAD_RRI#HI#CALM"        : 10,
    "IMAD_RIR#HI#CALM"        : 10,
    "IMAD_RRC#HI#CALM"        : 10,
    "IMAD_RCR#HI#CALM"        : 10,
    "IMAD_RRU#HI#CALM"        : 10,
    "IMAD_RRU#HI#CALM"        : 10,
    "IMAD_RRR#WIDE#CALM"      : 10,
    "IMAD_RRI#WIDE#CALM"      : 10,
    "IMAD_RIR#WIDE#CALM"      : 10,
    "IMAD_RRC#WIDE#CALM"      : 10,
    "IMAD_RCR#WIDE#CALM"      : 10,
    "IMAD_RRU#WIDE#CALM"      : 10,
    "IMAD_RRU#WIDE#CALM"      : 10,
    "IMAD_RRR#U32#CALM"       : 10,
    "IMAD_RRI#U32#CALM"       : 10,
    "IMAD_RIR#U32#CALM"       : 10,
    "IMAD_RRC#U32#CALM"       : 10,
    "IMAD_RCR#U32#CALM"       : 10,
    "IMAD_RRU#U32#CALM"       : 10,
    "IMAD_RRU#U32#CALM"       : 10,
    "IMAD_RRR#HIU32#CALM"     : 10,
    "IMAD_RRI#HIU32#CALM"     : 10,
    "IMAD_RIR#HIU32#CALM"     : 10,
    "IMAD_RRC#HIU32#CALM"     : 10,
    "IMAD_RCR#HIU32#CALM"     : 10,
    "IMAD_RRU#HIU32#CALM"     : 10,
    "IMAD_RRU#HIU32#CALM"     : 10,
    "IMAD_RRR#WIDEU32#CALM"   : 10,
    "IMAD_RRI#WIDEU32#CALM"   : 10,
    "IMAD_RIR#WIDEU32#CALM"   : 10,
    "IMAD_RRC#WIDEU32#CALM"   : 10,
    "IMAD_RCR#WIDEU32#CALM"   : 10,
    "IMAD_RRU#WIDEU32#CALM"   : 10,
    "IMAD_RRU#WIDEU32#CALM"   : 10,
}

IALU_map = InstructionMap("IALU_instructions", IALU_instructions)

IALUX_instructions ={
    "IADD_RR#X#CALM"           : 10,
    "IADD_RU#X#CALM"           : 10,
    "IADD_RI#X#CALM"           : 10,
    "IADD_RC#X#CALM"           : 10,
    "IADD_RR#XNoCarry#CALM"    : 10,
    "IADD_RU#XNoCarry#CALM"    : 10,
    "IADD_RI#XNoCarry#CALM"    : 10,
    "IADD_RC#XNoCarry#CALM"    : 10,
    "IADD_RR#R64X#CALM"        : 10,
    "IADD_RU#R64X#CALM"        : 10,
    "IADD_RI#R64X#CALM"        : 10,
    "IADD_RC#R64X#CALM"        : 10,
    "IADD_RR#R64XNoCarry#CALM" : 10,
    "IADD_RU#R64XNoCarry#CALM" : 10,
    "IADD_RI#R64XNoCarry#CALM" : 10,
    "IADD_RC#R64XNoCarry#CALM" : 10,
    "IMAD_RRR#X#CALM"          : 10,
    "IMAD_RRI#X#CALM"          : 10,
    "IMAD_RIR#X#CALM"          : 10,
    "IMAD_RRC#X#CALM"          : 10,
    "IMAD_RCR#X#CALM"          : 10,
    "IMAD_RRU#X#CALM"          : 10,
    "IMAD_RRU#X#CALM"          : 10,
    "IMAD_RRR#HIX#CALM"        : 10,
    "IMAD_RRI#HIX#CALM"        : 10,
    "IMAD_RIR#HIX#CALM"        : 10,
    "IMAD_RRC#HIX#CALM"        : 10,
    "IMAD_RCR#HIX#CALM"        : 10,
    "IMAD_RRU#HIX#CALM"        : 10,
    "IMAD_RRU#HIX#CALM"        : 10,
    "IMAD_RRR#WIDXE#CALM"      : 10,
    "IMAD_RRI#WIDXE#CALM"      : 10,
    "IMAD_RIR#WIDXE#CALM"      : 10,
    "IMAD_RRC#WIDXE#CALM"      : 10,
    "IMAD_RCR#WIDXE#CALM"      : 10,
    "IMAD_RRU#WIDXE#CALM"      : 10,
    "IMAD_RRU#WIDE#CALM"      : 10,
    "IMAD_RRR#U32X#CALM"       : 10,
    "IMAD_RRI#U32X#CALM"       : 10,
    "IMAD_RIR#U32X#CALM"       : 10,
    "IMAD_RRC#U32X#CALM"       : 10,
    "IMAD_RCR#U32X#CALM"       : 10,
    "IMAD_RRU#U32X#CALM"       : 10,
    "IMAD_RRU#U32X#CALM"       : 10,
    "IMAD_RRR#HIU32X#CALM"     : 10,
    "IMAD_RRI#HIU32X#CALM"     : 10,
    "IMAD_RIR#HIU32X#CALM"     : 10,
    "IMAD_RRC#HIU32X#CALM"     : 10,
    "IMAD_RCR#HIU32X#CALM"     : 10,
    "IMAD_RRU#HIU32X#CALM"     : 10,
    "IMAD_RRU#HIU32X#CALM"     : 10,
    "IMAD_RRR#WIDEU32X#CALM"   : 10,
    "IMAD_RRI#WIDEU32X#CALM"   : 10,
    "IMAD_RIR#WIDEU32X#CALM"   : 10,
    "IMAD_RRC#WIDEU32X#CALM"   : 10,
    "IMAD_RCR#WIDEU32X#CALM"   : 10,
    "IMAD_RRU#WIDEU32X#CALM"   : 10,
    "IMAD_RRU#WIDEU32X#CALM"   : 10,

}

IALUX_map = InstructionMap("IALU_instructions", IALUX_instructions)


ZFH_instructions = merge(ZFH32_instructions, ZFH64_instructions)
ZFH_map = InstructionMap("ZFH_instructions", ZFH_instructions)
